home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / Citizen.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  3.4 KB  |  121 lines

  1. class Citizen extends smashing.Renderable
  2. {
  3.    var update;
  4.    var myFloor;
  5.    var m;
  6.    var oBuildings;
  7.    var x;
  8.    var y;
  9.    var oCitizenHandler;
  10.    var r = 15;
  11.    var sType = "citizen";
  12.    var bounce = 500;
  13.    var bDead = true;
  14.    var nDie = 2;
  15.    var cDie = 0;
  16.    function Citizen()
  17.    {
  18.       super();
  19.       this.update = this.updateNormal;
  20.       this.myFloor = BuildingHandler.floor - this.r - 50;
  21.    }
  22.    function updateNormal(nElapsed)
  23.    {
  24.       this.m.y += smashing.Phys.gr * nElapsed;
  25.       var _loc10_ = this.oBuildings.oHandler.clips;
  26.       var _loc11_ = _loc10_.length;
  27.       var _loc7_ = undefined;
  28.       var _loc6_ = undefined;
  29.       var _loc3_ = undefined;
  30.       var _loc8_ = undefined;
  31.       var _loc9_ = new smashing.Point(this.x,this.y);
  32.       var _loc4_ = new smashing.Point(this.m.x * nElapsed,this.m.y * nElapsed);
  33.       if(this.y + _loc4_.y > this.myFloor)
  34.       {
  35.          this.m.x = 0;
  36.          this.m.y = 0;
  37.          this.x += _loc4_.x;
  38.          this.y = this.myFloor;
  39.          _loc4_.x = 0;
  40.          _loc4_.y = 0;
  41.          this.bDead = false;
  42.          this.update = this.updateDizzy;
  43.          this.gotoAndStop("land");
  44.       }
  45.       else
  46.       {
  47.          var _loc5_ = 0;
  48.          while(_loc5_ < _loc11_)
  49.          {
  50.             _loc7_ = _loc10_[_loc5_];
  51.             if(_loc7_.hitTest(this) == true)
  52.             {
  53.                _loc6_ = _loc7_.aLines;
  54.                _loc8_ = _loc6_.length;
  55.                var _loc2_ = 0;
  56.                while(_loc2_ < _loc8_)
  57.                {
  58.                   _loc3_ = _loc6_[_loc2_].collisionPointSwept(_loc9_,_loc4_,this.r);
  59.                   if(_loc3_ != null)
  60.                   {
  61.                      this.m.x = 0;
  62.                      this.m.y = 0;
  63.                      _loc4_.x = 0;
  64.                      _loc4_.y = 0;
  65.                      this.x = _loc3_.hit.x;
  66.                      this.y = _loc3_.hit.y;
  67.                      this.bDead = false;
  68.                      this.update = this.updateDizzy;
  69.                      this.gotoAndStop("land");
  70.                      break;
  71.                   }
  72.                   _loc2_ = _loc2_ + 1;
  73.                }
  74.             }
  75.             _loc5_ = _loc5_ + 1;
  76.          }
  77.       }
  78.       this.x += _loc4_.x;
  79.       this.y += _loc4_.y;
  80.    }
  81.    function updateDizzy(nElapsed)
  82.    {
  83.    }
  84.    function updateHit(nElapsed)
  85.    {
  86.       this.m.y += smashing.Phys.gr * nElapsed;
  87.       this.x += this.m.x * nElapsed;
  88.       this.y += this.m.y * nElapsed;
  89.    }
  90.    function render()
  91.    {
  92.       var _loc2_ = smashing.Viewport.getPos(this);
  93.       if(Math.abs(_loc2_.x) > smashing.Viewport.halfWidth + this.r)
  94.       {
  95.          this.oCitizenHandler.removeCitizen(this);
  96.       }
  97.       this._x = _loc2_.x + smashing.Viewport.centerX;
  98.       this._y = _loc2_.y + smashing.Viewport.centerY;
  99.    }
  100.    function collisionTest(oPlayer)
  101.    {
  102.       var _loc2_ = new smashing.Point(oPlayer.x - this.x,oPlayer.y - this.y);
  103.       var _loc4_ = _loc2_.y;
  104.       _loc2_.y += oPlayer.r * oPlayer.nCrouchMod * (_loc4_ / Math.abs(_loc4_));
  105.       var _loc5_ = Math.pow(this.r + oPlayer.r,2);
  106.       if(_loc2_.dot(_loc2_) < _loc5_)
  107.       {
  108.          return true;
  109.       }
  110.       return false;
  111.    }
  112.    function react(oPlayer, nElapsed)
  113.    {
  114.       oPlayer.hurt();
  115.       this.m = new smashing.Point(1,-1);
  116.       this.m.length = this.bounce;
  117.       this.bDead = true;
  118.       this.update = this.updateHit;
  119.    }
  120. }
  121.